﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bymed.SpineScan.DataModel;

namespace Bymed.SpineScan.Service.Validation
{
    public class AttendingDoctorValidator : DataValidatorBase<AttendingDoctor>
    {
        public const string NameErrorKey = "DoctorName";

        /// <summary>
        /// Validate the provided entity. Then check the IsValid property to see the result.
        /// </summary>
        /// <param name="entity">The provided entity to be validated.</param>
        public override void Validate(AttendingDoctor entity)
        {
            CheckRequiredName(entity);
            CheckNameLength(entity);
        }

        /// <summary>
        /// Check if the required name is provided.
        /// </summary>
        /// <param name="entity">The instance of AttendingDoctor.</param>
        /// <returns>True means passed. False means failed.</returns>
        public bool CheckRequiredName(AttendingDoctor entity)
        {
            if (!ValidationHelper.RuleCheckRequiredContent(entity.Name))
            {
                AddError(NameErrorKey, "医生姓名不能为空");
                return false;
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// Check the name's max length.
        /// </summary>
        /// <param name="entity">The instance of AttendingDoctor.</param>
        /// <returns>True means passed. False means failed.</returns>
        public bool CheckNameLength(AttendingDoctor entity)
        {
            int maxLength = 20;

            if (!ValidationHelper.RuleCheckMaxLength(maxLength, entity.Name))
            {
                AddError(NameErrorKey, string.Format("医生姓名长度不能超过{0}", maxLength));
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
